package com.googlecode.spruce.domain;

import java.io.Serializable;
import java.util.Set;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;

@Entity
@Table(name = "service")
public class Service implements Serializable
{

    /** Serial ID */
    private static final long serialVersionUID = 6503093483220756795L;

    @Id
    @Column(name = "id")
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Integer id;

    @Column(name = "plugin_name")
    private String pluginName;

    @ManyToOne
    @JoinColumn(name = "service_group_id")
    private ServiceGroup serviceGroup;

    @OneToMany(mappedBy = "service")
    private Set<ServiceResult> serviceResults;

    public Integer getId()
    {
        return id;
    }

    public void setId(final Integer id)
    {
        this.id = id;
    }

    /**
     * @return the pluginName
     */
    public String getPluginName()
    {
        return pluginName;
    }

    /**
     * @param pluginName
     *            the pluginName to set
     */
    public void setPluginName(final String pluginName)
    {
        this.pluginName = pluginName;
    }

    /**
     * @return the serviceGroup
     */
    public ServiceGroup getServiceGroup()
    {
        return serviceGroup;
    }

    /**
     * @param serviceGroup
     *            the serviceGroup to set
     */
    public void setServiceGroup(final ServiceGroup serviceGroup)
    {
        this.serviceGroup = serviceGroup;
    }

    /**
     * @return the serviceResults
     */
    public Set<ServiceResult> getServiceResults()
    {
        return serviceResults;
    }

    /**
     * @param serviceResults
     *            the serviceResults to set
     */
    public void setServiceResults(final Set<ServiceResult> serviceResults)
    {
        this.serviceResults = serviceResults;
    }

    /**
     * @see java.lang.Object#hashCode()
     */
    @Override
    public int hashCode()
    {
        return (pluginName == null) ? 0 : pluginName.hashCode();
    }

    /**
     * @see java.lang.Object#equals(java.lang.Object)
     */
    @Override
    public boolean equals(final Object obj)
    {
        if (this == obj)
        {
            return true;
        }
        if (obj == null)
        {
            return false;
        }
        if (getClass() != obj.getClass())
        {
            return false;
        }
        Service other = (Service) obj;
        if (pluginName == null)
        {
            if (other.pluginName != null)
            {
                return false;
            }
        }
        else if (!pluginName.equals(other.pluginName))
        {
            return false;
        }
        return true;
    }
}
